import { axiosMock, delayFn, randArrItem } from '@/services/axiosMock'
import type { IDictionaryListItem } from '..'

axiosMock('default', mock => {
  // 获取字典配置列表
  mock.onPost(`/tmsapi/dictionary/list`).reply(
    delayFn<IDictionaryListItem[]>(600, ({ data }) => {
      const list = []
      if (data.types.includes('dynamic_field')) list.push('订单')
      if (data.types.includes('address')) list.push('地址')
      if (data.types.includes('date')) list.push('时间')
      // 动态字段
      if (list.length) {
        let count = 0
        return {
          success: true,
          data: ['订单', '地址', '时间'].map((item, index) => {
            const id = ++count
            return {
              id,
              fid: 0,
              attrKey: item,
              attrValue: `{{${item}}}`,
              orderNum: index,
              childrenList: Array(randArrItem([1, 6, 11, 16]))
                .fill(null)
                .map((_d, i) => ({
                  id: ++count,
                  fid: id,
                  attrKey: `${item}字段${i}`,
                  attrValue: `{{${item}字段${i}}}`,
                  orderNum: i,
                })),
            }
          }),
        }
      }

      // 无
      return {
        success: true,
        data: [],
      }
    }),
  )
})
